<% content_for :title, "#{ @ad }" %>

<section class="main_content ad">
  <aside>
    <% if user_signed_in? %>
    <p><%= link_to "Répondre à l'annonce", new_offer_path(:ad => @ad.id) %></p>
    <% end %>
    <p><%= link_to 'Signaler un abus', report_ads_path(:ad => @ad.id), :confirm => 'Signaler cette annonce ?' %></p>
  </aside>
  <article>
    <figure>
      <%= image_tag @ad.picture.url(:medium) %>
      <figcaption><%= @ad.label %></figcaption>
    </figure>

    <header>
      <h1><%= @ad.label %></h1>
    </header>

    <p>Par <%= @ad.user.username %></p>

    <p>
      Équivalent en peaksel ? <%= @ad.cost %> <%= image_tag 'peak.png' %><br />
      Où ? <%= @ad.city %><br />
      Quand ? <%=l @ad.created_at %><br />
    </p>

    <p class="content"><%= @ad.description %></p>
    <p class="content">
      <% @ad.tags.each do |tag| %>
        <%= link_to tag, tag %>
      <% end %>
    </p>
  </article>

  <section>
    <% @ad.offers.each do |offer| %>
      <article id="offer">
        <header>
          <h1><%= offer.title %></h1>
        </header>

        <p><%= offer.content %></p>

        <% if user_signed_in? and @ad.user == current_user %>
        <p><%= link_to "Accepter l'offre", new_transaction_path(:offer => offer.id) %></p>
        <% end %>

      </article>

      <aside id="offer">
        <% offer.comments.each do |comment| %>
        <div>
          <h2><%= comment.title %></h2>
          <p><%= comment.content %></p>

            <% if user_signed_in? %>
            <p>
              <%=
                link_to 'Répondre à ' + comment.user.username,
                new_comment_path(:offer => offer.id, :comment => comment.id)
              %>
            </p>
            <% end %>
        </div>
        <% end %>
      </aside>
    <% end %>
  </section>
</section>
